package org.example.carsystem.config;

import lombok.extern.slf4j.Slf4j;
import org.example.carsystem.domain.vo.DeptVo;
import org.example.carsystem.mapper.DeptMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;


import javax.annotation.PostConstruct;

import java.util.List;


@Slf4j
@Configuration
public class RedisCache {
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private  DeptMapper deptMapper;
    @PostConstruct
    public void redisCacheDept(){
        log.info("进行dept部门缓存");
        if (Boolean.FALSE.equals(redisTemplate.hasKey("dept"))){
            log.info("查询所有部门放入redis缓存");
            List<DeptVo> list = deptMapper.deptSelectAll();
            redisTemplate.opsForValue().set("dept",list);
        }
    }
}
